$(function(){
	getdata.init();
})
//存储电影ID
var m_id = [];

var getdata = {
	init : function(){
		getdata.recommend();
		getdata.toMovieDetail();
	},
	//显示推荐电影
	recommend : function() {
        var recommendUrl = '/movie/recommend_usermovies.do';
        var u_id = localStorage.getItem("uid");
        if (u_id == null) {
            u_id = 0;
        }
        // console.log(u_id);
        console.log(u_id);
        var param = {
            u_id: u_id
        }
        if (u_id != 0) {
            var recommendTpl;
            publicDom.post(recommendUrl, param, function (response) {
                response = JSON.parse(response);
                if (response.msg != "没看过电影") {
                    if (response.code == 200) {
                        console.log(response);
                        for (var i = 0; i < response.object.length; i++) {
                            recommendTpl = '<li class="list">'
                                + '<div class="list-item">'
                                + '<div class="list-item-wrapper">'
                                + '<div class="p">'
                                + '<img class="p-pic" src=' + response.object[i].imgurl + '>'
                                + '</div>'
                                + '<div class="goods_info">'
                                + '<div class="goodsdetails">'
                                + '<p>' + response.object[i].m_name + '</p>'
                                + '</div>'
                                + '<p class="actor">主演:' + response.object[i].actor + '</p>'
                                + '</div>'
                                + '</div>'
                                + '</div>'
                                + '</li>';
                            $('.page-container').append(recommendTpl);
                            m_id.push(response.object[i].m_id);
                        }
                    }
                }
                else {
                    layer.msg("请去看电影吧");
                }
            })
        }
        else
		{
                layer.msg("请登录");
            }
    },

	//跳转到电影详情页面
	toMovieDetail : function(){
		var num;
		var u_id = localStorage.getItem("uid");
		$('.list').click(function(){
			num = $('.list').index(this);
			console.log(num);
			console.log(m_id[num]);
			window.location = "productDetail.html?u_id="+u_id+"&m_id="+m_id[num];
		});
	}
}